var mongoose=require('mongoose');
var User=mongoose.model('User',{
    name:String,
    number:Number,
    winner:Boolean,
    array:Array
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');


User.update({name:'A'},{number:1101,winner:true,array:[1,2]},{upsert:true},(e,r)=>{
    if(e)throw e;
    console.log('Update:\n',r);

    User.update({name:'B'},{number:1201,winner:false,array:[3,4]},{upsert:true},(e,r)=>{
        if(e)throw e;
        console.log('Update:\n',r);


        User.update({name:'C'},{number:1301,winner:true,array:[1,3]},{upsert:true},(e,r)=>{
            if(e)throw e;
            console.log('Update:\n',r);

            User.update({name:'D'},{number:1401,winner:false,array:[2,4]},{upsert:true},(e,r)=>{
                if(e)throw e;
                console.log('Update:\n',r);

                User.update({name:'E'},{number:1401,winner:false,array:[1,2,3]},{upsert:true},(e,r)=>{
                    if(e)throw e;
                    console.log('Update:\n',r);

                    User.find((e,r)=>{
                        if(e)throw e;
                        console.log('\nFind All:\n',JSON.stringify(r,null,2));

                        User.find({
                            array:[1,3]
                        },(e,r)=>{
                            if(e)throw e;
                            console.log('\nFind [1,3]:\n',JSON.stringify(r,null,2));

                            User.find({
                                array:1
                            },(e,r)=>{
                                if(e)throw e;
                                console.log('\nFind 1:\n',JSON.stringify(r,null,2));
                                process.exit(1);
                            });

                        });

                    });


                });


            });

        });

    });

});


/*
* field:[val1,val2...]
*
* 匹配数组字段的值完全相等于：val1,val2,...
*
* * field:val
*
* 匹配数组字段的值包含：val
* */
